package com.brossdong.socket.BIO;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by brossdong on 2018/1/29.
 * 服务端
 */
public class Server {

    final static int port = 8765;

    public static void main(String[] args) {

        ServerSocket server = null;
        try {
            server = new ServerSocket(port);
            System.out.println("server start...");
            //阻塞
            Socket socket = server.accept();
            //新建一个线程执行客户端
            new Thread(new ServerHandler(socket)).start();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (server != null) {
                try {
                    server.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        server = null;
    }

}
